home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / madtrb30.arc / JOYSTICK.PAS next >
Pascal/Delphi Source File  |  1985-05-06  |  4KB  |  92 lines

  1. Program TestJoystick; { TURBO Pascal program containing stick procedure }
  2.                       { and demonstration program. For use on IBM PC,   }
  3. {$c-}                 { PC-Jr etc.                                      }
  4.                       { If you have a monochrome monitor change         }
  5.                       { 'graphcolormode' to 'graphmode' (2 occurances)  }
  6. const
  7.   xymin = 3;        { These are the minimium and maximum values returned }
  8.   xymax = 106;      { from procedure stick. The numbers depend on the    }
  9.                     { joystick and the computer you are using.           }
  10. var
  11.   ix,iy,b1,b2:       integer;
  12.   xx,yy,xx1,yy1:     integer;
  13.   x1,x2,y1,y2:       integer;
  14.   adjx,adjy:         real;
  15.  
  16. procedure stick(var x,y,k1,k2: integer);   {procedure to get x and y}
  17.    begin                                   {coordinates of joystick #1}
  18.       inline                               {and to test joystick keys}
  19.         ($ba/$01/$02/   { MOV   DX,0201H } {1=pressed  0=not pressed}
  20.          $ec/           { IN    AL,DX    }
  21.          $a8/$03/       { TEST  AL,03H   }  { 0CH for joystick #2 }
  22.          $75/$fb/       { JNZ   $-3      }
  23.          $b9/$2c/$01/   { MOV   CX,300   }
  24.          $fa/           { CLI            }
  25.          $ee/           { OUT   DX,AL    }
  26.          $ec/           { IN    AL,DX    }
  27.          $a8/$01/       { TEST  AL,01H   }  { 04H for joystick #2 }
  28.          $e0/$fb/       { LOOPNZ $-3     }
  29.          $bb/$2c/$01/   { MOV   BX,300   }
  30.          $2b/$d9/       { SUB   BX,CX    }
  31.          $c4/$be/x/     { LES   DI,SS:x[BP] }
  32.          $26/$89/$1d/   { MOV   ES:[DI],BX  }
  33.          $2b/$db/       { SUB   BX,BX    }
  34.          $a8/$10/       { TEST  AL,10H   }  { 40H for joystick #2 }
  35.          $75/$03/       { JNZ   $+5      }
  36.          $83/$c3/$01/   { ADD   BX,1     }
  37.          $c4/$be/k1/    { LES   DI,SS:k1[BP] }
  38.          $26/$89/$1d/   { MOV   ES:[DI],BX   }
  39.          $2b/$db/       { SUB   BX,BX    }
  40.          $a8/$20/       { TEST  AL,20H   }  { 80H for joystick #2 }
  41.          $75/$03/       { JNZ   $+5      }
  42.          $83/$c3/$01/   { ADD   BX,1     }
  43.          $c4/$be/k2/    { LES   DI,SS:k2[BP] }
  44.          $26/$89/$1d/   { MOV   ES:[DI],BX   }
  45.          $ec/           { IN    AL,DX    }
  46.          $a8/$03/       { TEST  AL,03H   }  { 0CH for joystick #2 }
  47.          $75/$fb/       { JNZ   $-3      }
  48.          $b9/$2c/$01/   { MOV   CX,300   }
  49.          $ee/           { OUT   DX,AL    }
  50.          $ec/           { IN    AL,DX    }
  51.          $a8/$02/       { TEST  AL,02H   }  { 08H for joystick #2 }
  52.          $e0/$fb/       { LOOPNZ $-3     }
  53.          $fb/           { STI            }
  54.          $bb/$2c/$01/   { MOV   BX,300   }
  55.          $2b/$d9/       { SUB   BX,CX    }
  56.          $c4/$be/y/     { LES   DI,SS:y[BP] }
  57.          $26/$89/$1d);  { MOV   ES:[DI],BX  }
  58.    end;
  59.  
  60.  
  61. begin                             {sample program to demonstrate}
  62.   adjx:=319/(xymax-xymin);        {use of stick procedure}
  63.   adjy:=199/(xymax-xymin);        {press key #1 to clear screen}
  64.   graphcolormode;                 {press key #2 to terminate program}
  65.   stick(xx1,yy1,b1,b2);
  66.   repeat
  67.     stick(xx,yy,b1,b2);
  68.     if (xx>xx1+1) or (xx<xx1-1) or     { filter out very small }
  69.     (yy>yy1+1) or (yy<yy1-1) then      { movements of stick }
  70.     begin
  71. {     gotoxy(1,9);             }       { use these 4     }
  72. {     writeln('        ');     }       { statements to   }
  73. {     gotoxy(1,9);             }       { determine xymin }
  74. {     writeln(xx,' ',yy);      }       { and xymax       }
  75.       x1:=trunc((xx1-xymin)*adjx);
  76.       y1:=trunc((yy1-xymin)*adjy);
  77.       if y1>199 then y1:=199;
  78.       if x1>319 then x1:=319;
  79.       x2:=trunc((xx-xymin)*adjx);
  80.       y2:=trunc((yy-xymin)*adjy);
  81.       if y2>199 then y2:=199;
  82.       if x2>319 then x2:=319;
  83.       draw(x1,y1,x2,y2,1);
  84.       plot(x2,y2,2);
  85.       xx1:=xx;
  86.       yy1:=yy;
  87.     end;
  88.  
  89.     if b1<>0 then graphcolormode;     { clear screen }
  90.   until b2<>0;                        { return       }
  91. end.
  92.